package com.settlement.system.service.impl;

import com.settlement.system.mapper.TblWpBrandUnitConfigMapper;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblWpBrandUnitConfig;
import com.settlement.system.service.ITblWpBrandUnitConfigService;
import org.springframework.stereotype.Service;
import com.settlement.system.mapper.BaseMapper;
import jakarta.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 唯品会品牌对应配置 服务实现类
 * @author xiaochuan
 * @since 2020-04-09
 */
@Service
public class TblWpBrandUnitConfigServiceImpl extends BaseServiceImpl implements ITblWpBrandUnitConfigService {

    @Resource
    private TblWpBrandUnitConfigMapper tblWpBrandUnitConfigMapper;

    @Override
    public BaseMapper init() {
        return tblWpBrandUnitConfigMapper;
    }

    @Override
    public TblWpBrandUnitConfig getWpBrandByBrandUnitName(String brandUnitName) throws ServiceException {
        try {
            return tblWpBrandUnitConfigMapper.getWpBrandByBrandUnitName(brandUnitName);
        } catch (Exception e) {
            throw  new ServiceException(e);
        }
    }

    @Override
    public Map<String,String> getWpBrandMap() throws ServiceException {
        try {
            Map<String,String> map = new HashMap<>(16);
            List<TblWpBrandUnitConfig> list = tblWpBrandUnitConfigMapper.selectByParam(null);
            list.forEach(item->{
                map.put(item.getWpBrandName(),item.getBrandUnitName());
            });
            return map;
        } catch (Exception e) {
            throw  new ServiceException(e);
        }
    }

    /**
     * 获取品牌部对应关系
     * @param wpBrandName 唯品会品牌名称
     * @return
     * @throws ServiceException
     */
    @Override
    public List<TblWpBrandUnitConfig> getBrandUnitConfig(String wpBrandName, String vendorCode) throws ServiceException {
        try {
            return tblWpBrandUnitConfigMapper.getBrandUnitConfig(wpBrandName,vendorCode);
        } catch (Exception e) {
            throw new ServiceException("获取品牌部对应关系异常",e);
        }
    }
}

